father = {}
def initNode(n):
    for i in range(n):
        father[i] = i

def find(i):
    # 未进行路径压缩
    if father[i] == i:
        return i
    else:
        return find(father[i])

def union(i,j):
    # 把i的祖先节点放在j上
    fa_i = find(i)
    fa_j = find(j)
    
    father[fa_i] = fa_j

if __name__ == "__main__":
    initNode(5)

    union(4,3)
    union(3,2)
    union(2,1)
    union(1,0)
    print()
